#!/usr/bin/perl
use strict;
use warnings;

use Plack::App::URLMap;
use Plack::Builder;

my $envapp = sub {
    my $env = shift;
    #my $session = $env->{'psgix.session'};

    my @body = ( );
    foreach my $key (sort keys %{$env}) {
        push @body, "$key: '$env->{$key}'\n";
    }

    if (my $session = $env->{'psgix.session'}) {
        foreach my $key (sort keys %{$session}) {
            push @body, "psgix.session.$key: '$session->{$key}'\n";
        }
    }

    if (my $options = $env->{'psgix.session.options'}) {
        foreach my $key (sort keys %{$options}) {
            push @body, "psgix.session.options.$key: '$options->{$key}'\n";
        }
    }

    return [ 200, [ 'Content-Type' => 'text/plain;charset=UTF-8' ], \@body ];
};

my $urlmap = Plack::App::URLMap->new;
$urlmap->map("/" => $envapp);
$urlmap->map("/env" => $envapp);
$urlmap->map("/önv=x" => $envapp);
#$urlmap->map("http://bar.example.com/" => $app3);

builder {
    enable 'Session';
    enable "Auth::Basic", authenticator => sub {
        my($username, $password) = @_;
        return $username eq 'admin' && $password eq 'foobar';
    };
    $urlmap->to_app;
};
